﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RrslLite.Net.Proxies;
using Message = RrslLite.Net.Messages.Message;

namespace App.Test.Silverlight
{
    [TestClass]
    public class AsyncDuplexMessageProcessorProxyTEST
    {
        private static AsyncDuplexMessageProcessorProxy GetAsyncDuplexMessageProcessorProxy()
        {
            return new AsyncDuplexMessageProcessorProxy("pollingDuplex_IWcfDuplexMessageService");
        }

        [TestMethod]
        public void AsyncDuplexMessageProcessorProxy_cTor()
        {
            var testee = GetAsyncDuplexMessageProcessorProxy();

            Assert.IsNotNull(testee);
        }

        [TestMethod]
        public void AsyncDuplexMessageProcessorProxy_InvokeOperationsAsync()
        {
            var testee = GetAsyncDuplexMessageProcessorProxy();

            var messages = new Message[]
                               {
                                   new Message(Guid.NewGuid())
                                       {
                                           OperationContainerName = "IPersonFacade",
                                           OperationName = "GetActivePersonsFor",
                                           OperationParameters = new Dictionary<string,object>() { { "country", "CZ" } }
                                       },
                                   new Message(Guid.NewGuid())
                                       {
                                           OperationContainerName = "ICountryFacade",
                                           OperationName = "GetByCode",
                                           OperationParameters = new Dictionary<string,object>() { { "country", "CZ" } }
                                       }
                               };

            testee.ReceiveReceived += 
            (s, e) =>
            {
                Assert.IsNotNull(e.Result);
                Assert.IsTrue(e.Result.Length > 0);
            };

            testee.InvokeOperationsAsync(messages);
        }

        [TestMethod]
        public void AsyncDuplexMessageProcessorProxy_From_Generated_Proxy()
        {
            EndpointAddress address = new EndpointAddress("http://localhost:80/App.Host.Web/WcfDuplexMessageService.svc");
            PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding();

            //binding.CloseTimeout = new TimeSpan(0, 10, 0);

            var proxy = new ServiceReference2.WcfDuplexMessageServiceClient(binding, address);

            var messages = new ObservableCollection<ServiceReference2.Message>();

            proxy.ReceiveReceived += (s, e) =>
            {

            };

            proxy.InvokeOperationsAsync(new ServiceReference2.InvokeOperations(messages));
        }

    }
}
